using System;
using System.Data;
using PointOfSale.Global;

namespace PointOfSale.Class
{
	public class clsRoomDetail
	{
		private int roomId;
		private String roomNumber;
		private String guestName;
		private String checkIn;
		private String checkOut;

		public int RoomId{
			get{
				return roomId;
			}
			set{
				roomId = value;
			}
		}
		public String RoomNumber{
			get{
				return roomNumber;
			}
			set{
				roomNumber = value;
			}
		}
		public String GuestName
		{
			get
			{
				return guestName;
			}
			set
			{
				guestName = value;
			}
		}
		public String CheckIn{
			get{
				return checkIn;
			}
			set{
				checkIn = value;
			}
		}
		public String CheckOut{
			get{
				return checkOut;
			}
			set{
				checkOut = value;
			}
		}
		public clsRoomDetail()
		{
			guestName = "";
			roomNumber = "";
		}
		public clsRoomDetail(int rId)
		{
			String strSelect = "SELECT DISTINCT Phong.SoPhong AS [Room Name], NgayNhan AS [Check In Date], NgayTra AS [Check Out Date] FROM KhachPhong, Phong, Khach WHERE (( Phong.SoPhong = KhachPhong.SoPhong) AND (KhachPhong.KhachID = Khach.KhachID) AND (KhachPhong.LoaiSuDung = 1) AND (Phong.SoPhong = '" + rId +"'))";
			DataTable dt = clsDatabase.GetDataToTable(strSelect, clsGlobal.g_HMS_DataConn);
			clsRoomDetail room = new clsRoomDetail();
			roomId = rId;
			roomNumber = dt.Rows[0][0].ToString().Trim();
			checkIn = dt.Rows[0][1].ToString().Trim();
			checkOut = dt.Rows[0][2].ToString().Trim();
		}
		public static DataTable GetAllDetail()
		{
			String strSelect = "SELECT DISTINCT Phong.SoPhong AS [Room Name], NgayNhan AS [Check In Date], NgayTra AS [Check Out Date] FROM KhachPhong, Phong, Khach WHERE (( Phong.SoPhong = KhachPhong.SoPhong) AND (KhachPhong.KhachID = Khach.KhachID) AND (KhachPhong.LoaiSuDung = 1))";
			DataTable dt = clsDatabase.GetDataToTable(strSelect, clsGlobal.g_HMS_DataConn);
			return dt;
		}
		public static DataTable GetRoomDetail(String roomNumber)
		{
			String strSelect = "SELECT Khach.KhachID AS GuestId, KhachTen AS GuestName FROM Khach, KhachPhong WHERE ((Khach.KhachID = KhachPhong.KhachID) AND (KhachPhong.SoPhong = " + roomNumber + "))";
			DataTable dt = clsDatabase.GetDataToTable(strSelect, clsGlobal.g_HMS_DataConn);
			return dt;
		}
		public static clsRoomDetail GetGuestDetail(int guestId)
		{
			String strSelect = "SELECT KhachTen, KhachPhong.SoPhong AS Sophong FROM Khach, KhachPhong WHERE ((Khach.KhachID = KhachPhong.KhachID) AND (Khach.KhachID = " + guestId + "))";
			DataTable dt = clsDatabase.GetDataToTable(strSelect, clsGlobal.g_HMS_DataConn);
			clsRoomDetail roomDetail = new clsRoomDetail();
			if(dt.Rows.Count > 0)
			{
				roomDetail.GuestName = dt.Rows[0][0].ToString();
				roomDetail.RoomNumber = dt.Rows[0][1].ToString();
			}
			return roomDetail;
		}

		public static DataTable LayDanhSachPhong()
		{
			string selectCommand = "select distinct soPhong from KhachPhong where loaisudung=1 order by soPhong asc"; 
			DataTable dt = clsDatabase.GetDataToTable(selectCommand, clsGlobal.g_HMS_DataConn);
			return dt;
		}

		public static DataTable LayDanhSachKhach(int soPhong)
		{
			string selectCommand = "select khach.khachTen as khachTen, khachPhong.khachId as khachId from Khach  "
								+ "inner join KhachPhong on khach.khachId = khachPhong.khachId "
								+ " where KhachPhong.loaisudung= 1 and KhachPhong.soPhong = " + soPhong;
			DataTable dt = clsDatabase.GetDataToTable(selectCommand, clsGlobal.g_HMS_DataConn);
			return dt;
		}
	}
}
